const express = require('express');


const app = express();

// 声明中间件
app.use((req, res, next)=>{
      const referer = req.get('referer');
      console.log('referer->',referer)
      if(referer){
            let url = new URL(referer);
            let hostname = url.hostname;
            console.log('hostname==>',hostname)
            if(hostname !== '127.0.0.1'){
                  res.status(404).send('<h1> 404 not font </h1>');
                  return;
            }
      }
      next()
})

// 静态资源中间件
app.use(express.static(__dirname + '/public'))


app.listen(3000,()=>{
      console.log('启动')
})

// app.all('*',(req,res)=>{
//       res.send(`<h1> 404 not found </h1>`)
// })
